<template>
    <PageWrapper>
      <n-card :bordered="false" class="mb-3 proCard">
        <n-space align="center">
          <n-input-group style="width: 1280px">
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.title"
                clearable
                placeholder="请输入标题"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-select v-model:value="params.attr" placeholder="请选择属性" style="width: 200px;margin-left: 20px;" :options="optionsattr" clearable />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-select v-model:value="params.status" placeholder="请选择处理状态" style="width: 200px;margin-left: 20px;" :options="options" clearable />
            </div>
            <n-button type="primary" style="margin-left: 40px !important;" @click="reloadTable">
              <template #icon>
                <n-icon>
                  <SearchOutlined />
                </n-icon>
              </template>
              查询
            </n-button>
          </n-input-group>
        </n-space>
      </n-card>
      <n-card :bordered="false" class="proCard">
        <BasicTable
          :columns="columns"
          :request="loadDataTable"
          :row-key="(row) => row.id"
          ref="basicTableRef"
          :actionColumn="actionColumn"
          virtual-scroll
        >
        </BasicTable>
      </n-card>

      <CreateDrawer
        ref="createDrawerRef"
        :title="drawerTitle"
        :roleList="roleData"
        @change="reloadTable"
      />

    </PageWrapper>
  </template>
  
  <script lang="ts" setup>
    import { h, reactive, ref } from 'vue';
    import { BasicColumn, BasicTable, TableAction } from '@/components/Table';
    import { SearchOutlined } from '@vicons/antd';
    import CreateDrawer from './CreateDrawer.vue';
    import { columns } from './columns';
    import { list } from '@/api/work/index';

    const basicTableRef = ref();
    const tableData = ref();
    const createDrawerRef = ref();
    const drawerTitle = ref();
    const roleData = ref([]);
  
    const params = reactive({
      title: '',
      attr: null,
      status: null,
    });

    const optionsattr = ref([
      {
        label: "分润问题",
        value: 1,
      }, {
        label: '设备问题',
        value: 2
      }, {
        label: '修改手机号问题',
        value: 3
      },
    ])

    const options = ref([
      {
        label: "未处理",
        value: 1,
      },
      {
        label: '已处理',
        value: 2
      },
    ])

    // 操作
    const actionColumn: BasicColumn = reactive({
      width: 150,
      title: '操作',
      key: 'action',
      fixed: 'right',
      align: 'center',
      render(record) {
        if(record.status == 1){
          return h(TableAction as any, {
            actions: [
              {
                label: '去处理',
                onClick: handleEdit.bind(null, record),
              }
            ],
          });
        }
      },
    });
  
    //列表数据
    const loadDataTable = async (res) => {
      const result = await list({ ...params, ...res });
      tableData.value = result.list;
      return result;
    };

    // 编辑
    function handleEdit(record: Recordable) {
      drawerTitle.value = '编辑信息';
      const { openDrawer } = createDrawerRef.value;
      openDrawer(record.id);
    }

    //加载表格
    function reloadTable() {
      basicTableRef.value.reload();
    }
  
  </script>
  
<style lang="less" scoped>

</style>
  